<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSmsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //
        if(!Schema::hasTable('sms')){
            Schema::create('sms',function (Blueprint $table){
                $table->engine='InnoDB';
                $table->increments('id');
                $table->integer('fist_invest_status')->comment('首投状态 0全部，1已首投，2未首投');
                $table->integer('gender_status')->comment('性别选项 0全部，1男，2女');
                $table->integer('level')->comment('用户等级');
                $table->integer('min_age')->comment('最小年纪（含）');
                $table->integer('min_total_invest_num')->comment('最小总投资额（含）');
                $table->integer('realname_status')->comment('实名状态 0全部，1已实名，2未实名');
                $table->string('channel_code_list',100)->comment('渠道编号列表');
                $table->date('reg_end_time')->comment('结束注册时间');
                $table->date('reg_start_time')->comment('起始注册时间');
                $table->text('content',500)->comment('短信内容');
                $table->timestamps();
            });
        }
        if(!Schema::hasTable('sms_user')){
            Schema::create('sms_user',function(Blueprint $table){
                $table->engine='InnoDB';
                $table->integer('phone_num');
                $table->integer('sms_id')->unsigned();;
            });
            Schema::table('sms_user',function (Blueprint $table){
                $table->foreign('sms_id')
                    ->references('id')
                    ->on('sms')
                    ->onDelete('cascade')
                    ->onUpdate('restrict');
            });
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
        Schema::dropIfExists('sms');
        Schema::dropIfExists('sms_user');
    }
}
